# Import the error code configuration dictionary from the training configurations module.
from myapp.configs.training import ERROR_CODE_CONFIG


# This function retrieves a human-readable error message corresponding to a given error code.
def get_error_msg(error_code):
    # Check if the configuration exists and if an error code was provided.
    if not ERROR_CODE_CONFIG or not error_code:
        # If not, return a generic "unknown error" message.
        return '未知错误'
    # Look up the error code in the configuration and return the corresponding message.
    # If the code is not found, return the generic "unknown error" message.
    return ERROR_CODE_CONFIG.get('error_code', {}).get(error_code, '未知错误')


# This function checks if a given error code represents a state from which training can be resumed.
def can_continuing_training(error_code):
    # Check if the configuration exists and if an error code was provided.
    if not ERROR_CODE_CONFIG or not error_code:
        # If not, assume training cannot be continued.
        return False
    # Retrieve the list of error codes that permit continuing training from the configuration.
    continuing_training_error_code = ERROR_CODE_CONFIG.get('continuing_training_error_code', [])
    # Check if the provided error code is in the list of continuable error codes.
    if error_code in continuing_training_error_code:
        # If it is, return True.
        return True
    # Otherwise, return False.
    return False
